#!/usr/bin/python3
# -*- coding: UTF-8 -*-
import requests
from lxml import etree
from db.mysql import getConnection

url = 'https://movie.douban.com/subject/26348414/'
data = requests.get(url).text
s=etree.HTML(data)
fileName=s.xpath('//*[@id="content"]/h1/span[1]/text()')
fileDirector=s.xpath('//*[@id="info"]/span[1]/span[@class="attrs"]/a/text()')
print('电影名：',fileName)
print('导演：',fileDirector)

'''
###保存数据###
'''
def insertData():
	with getConnection() as db:
		sql = "insert into db_movie(name,director) values ('%s', '%s')"%(fileName[0], fileDirector[0])
		try:
			db.cursor.execute(sql)
			db.conn.commit()
		except Exception as e:
			print(e)

# insertData()